<template>
    <div
        style="padding-top: 40px"
        v-loading="pageLoading"
        element-loading-text="正在加载,请稍等"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(0, 0, 0, 0.8)"
    >
        <el-tabs type="border-card" v-model="activeName" @tab-click="handleClick">
            <el-tab-pane label="填写基础信息" name="first">
                <el-form :model="dataForm" ref="dataForm" label-width="120px">
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="产品编号">
                                <el-input v-model="dataForm.materialId" placeholder="" :disabled="isEdit"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="产品名称">
                                <el-input v-model="dataForm.materialName" placeholder="" :disabled="isEdit"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>

                    <el-row v-if="pageType === 'NCP'">
                        <el-col :span="12">
                            <el-form-item label="所属基地">
                                <el-select v-model="baseName" placeholder="请选择" style="width: 100%" :disabled="baseNameSelectedDis">
                                    <el-option
                                        v-for="(item, index) in baseNameptions"
                                        :key="index"
                                        :label="item.baseName"
                                        :value="item.baseId"
                                    >
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>

                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="所属分类" prop="parentId">
                                <el-popover
                                    ref="classifyListPopover"
                                    placement="bottom-start"
                                    :disabled="isEdit"
                                    trigger="click"
                                    v-model="visible2"
                                >
                                    <div style="overflow-y: auto; width: 200px; height: 200px">
                                        <el-tree
                                            :data="classifyList"
                                            :props="classifyListTreeProps"
                                            node-key="classifyId"
                                            ref="classifyListTree"
                                            @current-change="classifyListTreeCurrentChangeHandle"
                                            :default-expand-all="true"
                                            :highlight-current="true"
                                            :expand-on-click-node="false"
                                        ></el-tree>
                                    </div>
                                </el-popover>
                                <el-input
                                    v-model="dataForm.typeName"
                                    v-popover:classifyListPopover
                                    :readonly="true"
                                    :disabled="isEdit"
                                    placeholder="点击选择所属分类"
                                ></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>

                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="价格">
                                <el-input v-model="dataForm.price" placeholder="" :disabled="isEdit"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="库存">
                                <el-input v-model="dataForm.inventory" placeholder="" :disabled="isEdit"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>

                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="单位">
                                <el-input v-model="dataForm.unit" placeholder="" :disabled="isEdit"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>

                    <el-row>
                        <el-col :span="24">
                            <el-form-item label="详细介绍">
                                <quill-editor
                                    ref="text"
                                    v-model="dataForm.description"
                                    class="myQuillEditor"
                                    :disabled="isEdit"
                                    :options="editorOption"
                                />

                                <!-- <div v-html="dataForm.description"></div> -->

                                <!-- <el-input
                                    v-model="dataForm.description"
                                    placeholder=""
                                    type="textarea"
                                    :rows="10"
                                    :disabled="isEdit"
                                ></el-input> -->
                            </el-form-item>
                        </el-col>
                    </el-row>

                    <el-row>
                        <el-form-item label="商品图片">
                            <moreUpload
                                :initfileList="iconUrlListUrl"
                                :isMultiple="true"
                                :isUpdisable="!isEdit"
                                :upFileNum="5"
                                @moreUpFileHandleRemove="iconMoreUpFileHandleRemove"
                                @update="updateIconUrl"
                            ></moreUpload>
                        </el-form-item>
                    </el-row>

                    <el-row>
                        <el-form-item label="商品视频">
                            <moreUpVideo
                                :isShowFileList="true"
                                :isMultiple="true"
                                :isUpdisable="!isEdit"
                                :isClickClearList="false"
                                :upFileNum="5"
                                :initfileList="videoUrlListUrl"
                                @moreUpFileSuccessHandle="moreUpVideoSuccessHandle"
                                @moreUpFileHandleRemove="moreUpVideohandleRemove"
                                @moreUpFileErrorHandle="moreUpVideoFileErrorHandle"
                                @moreUpFileHandleExceed="moreUpVideoFileHandleExceed"
                            >
                            </moreUpVideo>
                        </el-form-item>
                    </el-row>

                    <el-row>
                        <div class="dialog-footer" style="margin: 30px 10px 30px 60px">
                            <!-- <el-button @click="$router.go(-1)">取消</el-button>
                            <el-button type="primary" @click="dataFormSubmit()">保存，下一步</el-button> -->
                        </div>
                    </el-row>
                </el-form>
            </el-tab-pane>

            <el-tab-pane label="填写产品属性" name="second">
                <el-form :model="dataCpSxForm" ref="dataCpSxForm" label-width="120px">
                    <div v-if="pageType === 'NCP'">
                        <el-row>
                            <el-col :span="12">
                                <h3 class="small-title">规格设置</h3>
                            </el-col>
                            <el-col :span="12">
                                <el-button icon="el-icon-plus" type="primary" size="mini" @click="addGGset">新增规格</el-button>
                            </el-col>
                        </el-row>

                        <el-row style="margin: 30px 30px 30px 0px">
                            <el-col :span="14">
                                <TableList
                                    tableRef="table"
                                    ref="multipleTable"
                                    :checkBoxEnable="false"
                                    :showPagination="false"
                                    :data="ggsetDataList ? ggsetDataList : []"
                                    :listConfig="ggsetResultColConfig"
                                    :listLoading="ggsetListLoading"
                                    @actionClick="ggsetActionClick"
                                ></TableList>
                            </el-col>
                        </el-row>
                    </div>

                    <el-row style="margin-top: 30px">
                        <el-col :span="12">
                            <h3 class="small-title">参数设置</h3>
                        </el-col>
                        <el-col :span="12">
                            <el-button icon="el-icon-plus" type="primary" size="mini" @click="addCSset">新增参数</el-button>
                        </el-col>
                    </el-row>

                    <el-row style="margin: 30px 30px 30px 0px">
                        <el-col :span="14">
                            <TableList
                                tableRef="table"
                                ref="multipleTable"
                                :checkBoxEnable="false"
                                :showPagination="false"
                                :data="cssetDataList ? cssetDataList : []"
                                :listConfig="cssetResultColConfig"
                                :listLoading="cssetListLoading"
                                @actionClick="cssetActionClick"
                            ></TableList>
                        </el-col>
                    </el-row>
                </el-form>
            </el-tab-pane>

            <el-tab-pane label="检验报告" name="three">
                <el-form :model="dataJyBgForm" ref="dataJyBgForm" label-width="120px">
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="检测方式">
                                <el-input v-model="dataJyBgForm.examWay" placeholder="" :disabled="isEdit"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>

                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="检测结果">
                                <el-input v-model="dataJyBgForm.examResult" placeholder="" :disabled="isEdit"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>

                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="检测时间">
                                <el-date-picker
                                    v-model="dataJyBgForm.examTime"
                                    type="datetime"
                                    placeholder="选择日期时间"
                                    value-format="yyyy-MM-dd HH:mm:ss"
                                    :disabled="isEdit"
                                >
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="认证方式">
                                <el-input v-model="dataJyBgForm.authenticationWay" placeholder="" :disabled="isEdit"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="检测员">
                                <el-input v-model="dataJyBgForm.inspector" placeholder="" :disabled="isEdit"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="检测单位">
                                <el-input v-model="dataJyBgForm.checkUnit" placeholder="" :disabled="isEdit"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>

                    <el-row>
                        <el-form-item label="检测报告">
                            <!-- <moreUpload :img="dataJyBgForm.checkReport" @update="checkReportUrl"></moreUpload> -->

                            <moreUpFile
                                :isShowFileList="true"
                                :isMultiple="true"
                                :upFileNum="5"
                                :isUpdisable="!isEdit"
                                :initfileList="checkReportListUrl"
                                @moreUpFileSuccessHandle="SuccessHandle"
                                @moreUpFileErrorHandle="moreUpFileErrorHandle"
                                @moreUpFileHandleRemove="moreUpFileHandleRemove"
                                @moreUpFileHandleExceed="moreUpFileHandleExceed"
                            >
                            </moreUpFile>

                            <!-- <viewer :images="dataJyBgForm.checkReport">
                                <img :src="dataJyBgForm.checkReport" class="viewer_img" />
                            </viewer> -->
                        </el-form-item>
                    </el-row>

                    <el-row>
                        <div class="dialog-footer" style="margin: 30px 10px 30px 60px">
                            <!-- <el-button @click="$router.go(-1)">取消</el-button>
                        
                            <el-button type="primary" @click="dataJyBgFormSubmit()">保存</el-button> -->
                        </div>
                    </el-row>
                </el-form>
            </el-tab-pane>
        </el-tabs>

        <div style="margin: 30px 10px 60px 10px">
              
            <div>
                <span>审核情况</span>
            </div>

            <div style="margin: 30px 30px 60px 30px">
                <el-row :gutter="8">
                    <el-col :span="6"> <div>审批人</div> </el-col>
                    <el-col :span="18">
                        <el-col :span="6"><div>审核状态</div></el-col>
                        <el-col :span="6"><div>审批时间</div></el-col>
                        <el-col :span="6"><div>审批原因</div></el-col>
                    </el-col>
                </el-row>
                <el-row :gutter="20" style="margin-top: 12px">
                    <el-col :span="6">
                        <div v-for="(item, index) in flowLogRes" :key="index" :title="item.curApproverId" :style="item.style">
                            {{ item.curApproverId }}
                        </div>
                    </el-col>

                    <el-col :span="18">
                        <div v-for="(item, index) in flowLogRes" :key="index" :style="item.style">
                            <el-row>
                                <el-col :span="6">
                                    <div>{{ item.status }}</div>
                                </el-col>

                                <el-col :span="6">
                                    <div>{{ item.approveTime }}</div>
                                </el-col>

                                <el-col :span="6">
                                    <div>{{ item.advise }}</div>
                                </el-col>
                            </el-row>
                        </div>
                    </el-col>
                </el-row>
            </div>
        </div>

        <div v-if="this.opShow">
            <div class="dialog-footer" style="margin: 30px 10px 30px 10px">
                <span>审批原因</span>

                <el-input
                    v-model="remark"
                    placeholder="请输入原因"
                    type="textarea"
                    style="margin-bottom: 20px; margin-top: 20px"
                ></el-input>

                <span slot="footer">
                    <el-button type="primary" @click="dataFormSubmit(1)">通过</el-button>
                    <el-button type="primary" @click="dataFormSubmit(2)">拒绝</el-button>
                    <el-button @click="closePage()">取消</el-button>
                </span>
            </div>
        </div>

        <ggSetAddOrUpdate ref="ggSetAddOrUpdateDom" @refreshDataList="ggSetListShow" v-show="ggSetAddOrUpdateVisible" />

        <csSetAddOrUpdate ref="csSetAddOrUpdateDom" @refreshDataList="csSetListShow" v-show="csSetAddOrUpdateVisible" />
    </div>
</template>
<script>
import API from '@/api';
import cloneDeep from 'lodash/cloneDeep';

import moreUpload from '../../../components/upLoad/moreUpload';
import moreUpFile from '../../../components/upLoad/moreUpFile';
import moreUpVideo from '../../../components/upLoad/moreUpVideo';

import TableList from '../../../components/TableList';
import ggSetAddOrUpdate from './ggset-add-or-update';
import csSetAddOrUpdate from './csset-add-or-update';

import { GGSET_RESULT_ITEMS, CCSET_RESULT_ITEMS } from './config';

import { quillEditor } from 'vue-quill-editor';
import 'quill/dist/quill.core.css';
import 'quill/dist/quill.snow.css';
import 'quill/dist/quill.bubble.css';

export default {
    components: {
        moreUpload,
        moreUpFile,
        moreUpVideo,
        TableList,
        ggSetAddOrUpdate,
        csSetAddOrUpdate,
        quillEditor
    },
    data() {
        return {
            pageLoading: false,
            visible: false,
            isEdit: true,
            //- 填写基础信息
            dataForm: {
                materialId: '', //产品编号
                materialName: '', //产品名称
                baseId: '', //所属基地

                typeId: '', //所属分类
                typeName: '',

                price: '', //价格
                inventory: '', //库存
                unit: '', //单位
                description: '', //详细介绍
                iconUrl: '', //商品图片
                videoUrl: '' //商品视频
            },

            editorOption: {},

            //商品图片
            iconUrlList: [],
            iconUrlListUrl: [],

            //商品视频
            videoUrlList: [],
            videoUrlListUrl: [],

            //所属基地
            baseName: '',
            baseNameSelectedDis: true,
            baseNameptions: [],

            //所属分类
            classifyList: [],
            classifyListTreeProps: {
                label: 'name',
                children: 'childrens'
            },

            //- 填写产品属性
            dataCpSxForm: {},

            //规格列表
            ggSetAddOrUpdateVisibleL: false,
            ggsetListLoading: false, // 数据列表显示状态
            ggsetResultColConfig: GGSET_RESULT_ITEMS,
            ggsetDataList: [], //  规格数据列表

            //参数列表
            csSetAddOrUpdateVisibleL: false,
            cssetListLoading: false, // 数据列表显示状态
            cssetResultColConfig: CCSET_RESULT_ITEMS,
            cssetDataList: [], //  参数数据列表

            //- 检测报告
            dataJyBgForm: {
                examWay: '', //检测方式
                examResult: '', //检测结果
                examTime: '', //检测时间
                authenticationWay: '', //认证方式
                inspector: '', //检测员
                checkUnit: '', //检测单位
                checkReport: '' //检测报告
            },

            //检测附件
            checkReportList: [],
            checkReportListUrl: [],

            //- 审批
            remark: '',

            //- 公用
            opShow: true,
            pageType: '',
            pageFlag: '',
            pageData: null,

            activeName: 'first'
        };
    },
    mounted() {
        var itemData = this.$route.query.itemData;
        var type = this.$route.query.type;
        this.pageType = this.$route.query.pageType;
        if (type == 2) {
            var id = itemData.materialId;

            this.getPageDeail(id, itemData.opFlag); // 获取基本信息
        } else {
            this.getBaseList(); //获取基地信息
            this.getClassifyList(); //获取所属分类
        }

        this.dialogType = type;
    },

    methods: {
        handleClick(tab, event) {
            console.log(tab, event);
        },
        handleClose() {
            this.dataForm = {};
            this.$refs['dataForm'].resetFields();
        },
        // 获取页面详情
        getPageDeail(materialId, opFlag) {
            //详情
            var _that = this;

            var tick;
            let params = {
                materialId: materialId
            };

            switch (this.$route.path) {
                case '/goodsManger/publicProductsAudit/ncp/audit':
                    //农产品管理 添加和编辑
                    tick = API.goodsManger.ncpDetails(params);

                    break;

                case '/goodsManger/publicProductsAudit/nz/audit':
                    //农资产品管理  添加和编辑
                    tick = API.goodsManger.nzDetails(params);

                    break;
            }

            _that.pageLoading = true;

            //详情
            tick.then((res) => {
                console.log(res);

                _that.pageData = res.result;

                _that.dataForm = _that.pageData;
                // //基本信息 赋值
                // Object.keys(_that.dataForm).forEach((key) => {
                //     console.log(key);
                //     _that.dataForm[key] = _that.pageData[key];
                // });

                //处理图片
                var imgUrlQz = window.baseUrl + '/sys/file/showpic?id=';

                //======= 字符串，拆分id数组，拆分Url数组，拆分标识，url前缀
                this.disposePublicStrSplit(_that.pageData.iconUrl, _that.iconUrlList, _that.iconUrlListUrl, 'url', imgUrlQz);

                //处理视频
                //======= 字符串，拆分id数组，拆分Url数组，拆分标识，url前缀
                this.disposePublicStrSplit(_that.pageData.videoUrl, _that.videoUrlList, _that.videoUrlListUrl, 'id', '');

                //所属基地
                if (this.pageType === 'NCP') {
                    _that.baseName = _that.pageData.baseName;
                }

                //产品属性
                _that.ggsetDataList = res.result.iaMaterialStandReqs; //规格
                _that.cssetDataList = res.result.iaMaterialParamReqs; //参数

                //检测
                Object.keys(_that.dataJyBgForm).forEach((key) => {
                    console.log(key);
                    _that.dataJyBgForm[key] = _that.pageData[key];
                });

                //处理检验报告
                //======= 字符串，拆分id数组，拆分Url数组，拆分标识，url前缀
                this.disposePublicStrSplit(_that.dataJyBgForm.checkReport, _that.checkReportList, _that.checkReportListUrl, 'id', '');

                //审批情况 审批流程列表
                _that.flowLogRes = res.result.flowLogRes;
                if (_that.flowLogRes != null) {
                    for (let index = 0; index < _that.flowLogRes.length; index++) {
                        let element = _that.flowLogRes[index];

                        //样式处理
                        if (index == 0) {
                            element.style = 'margin-top: 0px;';
                        } else {
                            element.style = 'margin-top: 40px;';
                        }

                        //审核状态处理
                        switch (element.status) {
                            // 审核状态：2-已提交 3-已提交  4-审核驳回 5-审核通过
                            case 2:
                                element.status = '待处理';
                                break;
                            case 3:
                                element.status = '已提交';
                                break;
                            case 4:
                                element.status = '审核驳回';
                                break;
                            case 5:
                                element.status = '审核通过';
                                break;
                        }
                    }
                }

                //审批完成隐藏所有操作按钮
                if (_that.pageData.flowStatusEnumStr != null && _that.pageData.flowStatusEnumStr === '审核通过(完成)') {
                    this.opShow = false;
                }

                //详情进入隐藏所有操作按钮
                if (opFlag === '1') {
                    this.opShow = false;
                }

                _that.pageLoading = false;
                _that = null;
            });

            this.getBaseList(); //获取基地信息
            this.getClassifyList(); //获取所属分类
        },

        disposePublicStrSplit(fileStr, splicList, splicUrlList, splicFlag, urlConnection) {
            //字符串，拆分id数组，拆分Url数组，拆分标识，url前缀

            if (fileStr != null && fileStr !== '') {
                //== 1.拆分字符串 ’a:b,b:a‘ 为数组
                splicList = fileStr.split(',');

                for (let index = 0; index < splicList.length; index++) {
                    //== 2.数组中的 ’a:b‘ 在拆分 为数组
                    const element = splicList[index];
                    var elmentList = element.split(':');

                    //== 3.向 上传 绑定的数据集，添加[name，url，id] 数据
                    if (elmentList.length > 0) {
                        if (splicFlag === 'url') {
                            //文件名，文件地址（url)，文件id
                            splicUrlList.push({ name: elmentList[1], url: urlConnection + elmentList[0], urlId: elmentList[0] });
                        } else {
                            //文件名，文件地址(可id或url)，文件id
                            splicUrlList.push({ name: elmentList[1], url: elmentList[0], urlId: elmentList[0] });
                        }
                    } else {
                        //== 3.x  做预防,有可能字符串为’a,b‘ 没有分号

                        if (splicFlag === 'url') {
                            splicUrlList.push({ name: '文件' + index, url: urlConnection + element, urlId: element });
                        } else {
                            //文件名，文件地址(可id或url)，文件id
                            splicUrlList.push({ name: '文件' + index, url: element, urlId: element });
                        }
                    }
                }
            }
        },

        //======= 填写基本信息
        //所属基地
        getBaseList() {
            let params = {};
            params.pageNum = 1;
            params.pageSize = 1000;
            API.base.baseList(params).then((res) => {
                this.baseNameptions = res.result.rows;
                if (this.dialogType == 2) {
                    //编辑时 取列表数据 （在详情获取时，已赋值）
                } else {
                    //新增时 默认第一个
                    if (this.baseNameptions.length > 0) {
                        this.dataForm.baseId = this.baseNameptions[0].baseId;
                        this.baseName = this.baseNameptions[0].baseName;
                    }
                }
            });
        },
        //所属分类
        getClassifyList() {
            //所属分类列表
            let flSlListparams = {};

            switch (this.$route.path) {
                case '/goodsManger/publicProductsAudit/ncp/audit':
                    //农产品管理-添加和编辑

                    flSlListparams.plate = 'CORPS';
                    this.pageFlag = '农产品管理-添加和编辑';

                    break;

                case '/goodsManger/publicProductsAudit/nz/audit':
                    //农资产品管理-添加和编辑
                    this.pageFlag = '农资产品管理-添加和编辑';

                    flSlListparams.plate = 'APRODUCT';

                    break;
            }

            //所属分类列表
            API.goodsManger.getList(flSlListparams).then((res) => {
                this.classifyList = res.result;
            });
        },

        //所属分类
        // 树选中
        classifyListTreeCurrentChangeHandle(data, node) {
            console.log(data);
            this.dataForm.typeId = data.classifyId;
            this.dataForm.typeName = data.name;
            this.visible2 = false;
        },
        // 树设置当前选中节点
        classifyListTreeSetCurrentNode() {
            this.$refs.classifyListTree.setCurrentKey(this.dataForm.parentId);
            this.dataForm.typeName = (this.$refs.classifyListTree.getCurrentNode() || {})['name'];
        },

        /**
         * 商品图片 上传
         */

        // 商品图片 上传文件  成功回调
        updateIconUrl([url, sigleImgId, response, file, fileList]) {
            this.diosposeImageOp([file, fileList]);
        },
        // 删除文件回调
        iconMoreUpFileHandleRemove([file, fileList]) {
            this.diosposeImageOp([file, fileList]);
        },
        diosposeImageOp([file, fileList]) {
            this.iconUrlList = [];

            for (let index = 0; index < fileList.length; index++) {
                const element = fileList[index];
                console.log('上传的商品图片：', element);

                if (element.response != null) {
                    //不等于空为刚上传的文件
                    this.iconUrlList.push(element.response.result[0] + ':' + element.name);
                } else {
                    //为空为之前上传的文件
                    this.iconUrlList.push(element.urlId + ':' + element.name);
                }
            }
        },

        /**
         * 商品视频 上传
         */

        //商品视频 上传文件  成功回调
        moreUpVideoSuccessHandle([url, sigleImgId, response, file, fileList]) {
            this.diosposeFileOp([file, fileList]);
        },
        // 删除文件回调
        moreUpVideohandleRemove([file, fileList]) {
            this.diosposeFileOp([file, fileList]);
        },
        diosposeFileOp([file, fileList]) {
            this.videoUrlList = [];

            for (let index = 0; index < fileList.length; index++) {
                const element = fileList[index];
                console.log('商品视频多文件上传回调：', element);

                if (element.response != null) {
                    //不等于空为刚上传的文件
                    this.videoUrlList.push(element.response.result[0] + ':' + element.name);
                } else {
                    //为空为之前上传的文件
                    this.videoUrlList.push(element.urlId + ':' + element.name);
                }
            }
        },

        //商品视频 上传文件 失败回调
        moreUpVideoFileErrorHandle(val) {
            this.$message.error(`文件上传失败`);
        },

        //商品视频 多文件上传，超出限制回调
        moreUpVideoFileHandleExceed([files, fileList]) {
            this.$message.warning(
                `当前限制选择 5 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`
            );
        },

        getBaseNameptions(params, name) {
            if (this.isChinese(name)) {
                //全是中文，代表用户没有选择，为默认值，或者
                for (var i = 0; i < this.baseNameptions.length; i++) {
                    if (this.baseNameptions[i].baseName === name) {
                        this.dataForm.baseId = this.baseNameptions[i].baseId;
                        params.baseId = this.baseNameptions[i].baseId;

                        return this.baseNameptions[i].baseId;
                    }
                }
            } else {
                //选择之后，name为代码id
                for (var i = 0; i < this.baseNameptions.length; i++) {
                    if (this.baseNameptions[i].baseId === name) {
                        this.dataForm.baseId = this.baseNameptions[i].baseId;
                        params.baseId = this.baseNameptions[i].baseId;

                        return this.baseNameptions[i].baseId;
                    }
                }
            }
        },

        //是否全是 中文
        isChinese(temp) {
            var re = /[^\u4e00-\u9fa5]/;
            if (re.test(temp)) return false;
            return true;
        },

        // 基本上信息提交
        dataFormSubmit() {
            this.$refs['dataForm'].validate((valid) => {
                if (valid) {
                    let params = cloneDeep(this.dataForm);

                    //图片和视频校验
                    if (this.dialogType == 1) {
                        if (this.iconUrlList.length == 0 && this.videoUrlList.length == 0) {
                            this.$message.error('商品图片和视频，需要任意选择一个上传');
                            return;
                        }
                    } else {
                        if (this.iconUrlListUrl.length == 0 && this.videoUrlListUrl.length == 0
                        &&this.iconUrlList.length == 0 && this.videoUrlList.length == 0) {
                            this.$message.error('商品图片和视频，需要任意选择一个上传');
                            return;
                        }
                    }

                    //处理商品图片
                    if (this.iconUrlList.length > 0) {
                        this.dataForm.iconUrl = this.iconUrlList.join(',');
                        params.iconUrl = this.dataForm.iconUrl;
                    }

                    //处理商品视频
                    if (this.videoUrlList.length > 0) {
                        this.dataForm.videoUrl = this.videoUrlList.join(',');
                        params.videoUrl = this.dataForm.videoUrl;
                    }

                    //处理所属基地选择
                    if (this.pageType === 'NCP') {
                        this.getBaseNameptions(params, this.baseName);
                    }

                    console.log('传递的数据：', params);
                    var tick;
                    switch (this.$route.path) {
                        case '/goodsManger/publicProductsAudit/ncp/audit':
                            //农产品管理 添加和编辑
                            tick = this.dialogType == 1 ? API.goodsManger.ncpAddBase(params) : API.goodsManger.ncpUpdateBase(params);

                            break;

                        case '/goodsManger/publicProductsAudit/nz/audit':
                            //农资产品管理  添加和编辑
                            tick = this.dialogType == 1 ? API.goodsManger.nzAddBase(params) : API.goodsManger.nzUpdateBase(params);

                            break;
                    }

                    tick.then((data) => {
                        if (data.code == '0000') {
                            this.$message({
                                message: `${this.dialogType == 2 ? '修改保存成功' : '保存成功'}`,
                                type: 'success',
                                duration: 1500,
                                onClose: () => {
                                    //切换 tab
                                    this.activeName = 'second';
                                }
                            });
                        }
                    });
                }
            });
        },

        //======= 填写产品属性

        //规格
        addGGset() {
            this.ggSetAddOrUpdateVisibleL = true;
            this.$refs.ggSetAddOrUpdateDom.init(null, this.dataForm, this.pageFlag);
        },

        ggSetListShow() {
            let params = {
                materialId: this.dataForm.materialId
            };

            API.goodsManger.ncpGetStandList(params).then((res) => {
                this.ggsetDataList = res.result;
            });
        },

        ggsetActionClick([data, item]) {
            if (item.alias === 'edit') {
                this.ggSetAddOrUpdateVisibleL = true;
                this.$refs.ggSetAddOrUpdateDom.init(data, this.pageData, this.pageFlag);
            } else if (item.alias === 'del') {
                this.ggSetListDel(data);
            }
        },
        ggSetListDel(data) {
            let params = {
                standId: data.standId
            };

            API.goodsManger.ncpStandListDel(params).then((res) => {
                if (res.code == '0000') {
                    this.$message({
                        type: 'success',
                        message: `删除成功`
                    });
                    this.ggSetListShow();
                }
            });
        },

        //参数
        addCSset() {
            this.csSetAddOrUpdateVisibleL = true;
            this.$refs.csSetAddOrUpdateDom.init(null, this.dataForm, this.pageFlag);
        },

        csSetListShow() {
            let params = {
                materialId: this.dataForm.materialId
            };
            let tick;
            switch (this.pageFlag) {
                case '农产品管理-添加和编辑':
                    tick = API.goodsManger.ncpGetParamList(params);

                    break;

                case '农资产品管理-添加和编辑':
                    tick = API.goodsManger.nzGetParamList(params);
                    break;
            }

            tick.then((res) => {
                this.cssetDataList = res.result;
            });
        },

        cssetActionClick([data, item]) {
            if (item.alias === 'edit') {
                this.csSetAddOrUpdateVisibleL = true;
                this.$refs.csSetAddOrUpdateDom.init(data, this.pageData, this.pageFlag);
            } else if (item.alias === 'del') {
                this.csSetListDel(data);
            }
        },
        csSetListDel(data) {
            let params = {
                paramId: data.paramId
            };

            let tick;
            switch (this.pageFlag) {
                case '农产品管理-添加和编辑':
                    tick = API.goodsManger.ncpParamListtDel(params);

                    break;

                case '农资产品管理-添加和编辑':
                    tick = API.goodsManger.nzParamListtDel(params);
                    break;
            }

            tick.then((res) => {
                if (res.code == '0000') {
                    this.$message({
                        type: 'success',
                        message: `删除成功`
                    });
                    this.csSetListShow();
                }
            });
        },

        //======= 检验报告

        // 图片
        //检测报告 上传文件  成功回调
        SuccessHandle([url, sigleImgId, response, file, fileList]) {
            this.diosposeJYBGFileOp([file, fileList]);
        },

        //检验报告 上传文件 删除回调
        moreUpFileHandleRemove([file, fileList]) {
            this.diosposeJYBGFileOp([file, fileList]);
        },

        diosposeJYBGFileOp([file, fileList]) {
            this.checkReportList = [];

            for (let index = 0; index < fileList.length; index++) {
                const element = fileList[index];
                console.log('检测报告文件上传回调：', element);

                if (element.response != null) {
                    //不等于空为刚上传的文件
                    this.checkReportList.push(element.response.result[0] + ':' + element.name);
                } else {
                    //为空为之前上传的文件
                    this.checkReportList.push(element.urlId + ':' + element.name);
                }
            }
        },

        //检测报告 上传文件 失败回调
        moreUpFileErrorHandle(val) {
            this.$message.error(`文件上传失败`);
        },

        //检测报告 多文件上传，超出限制回调
        moreUpFileHandleExceed([files, fileList]) {
            this.$message.warning(
                `当前限制选择 5 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`
            );
        },

        dataJyBgFormSubmit() {
            let params = cloneDeep(this.dataJyBgForm);
            params.materialId = this.dataForm.materialId;

            //检测报告 上传处理
            if (this.checkReportList.length > 0) {
                this.dataJyBgForm.checkReport = this.checkReportList.join(',');
                params.checkReport = this.dataJyBgForm.checkReport;
            }

            var tick;

            switch (this.pageFlag) {
                case '农产品管理-添加和编辑':
                    if (this.type == 1) {
                        tick = API.goodsManger.ncpAddOperateExamReport(params);
                    } else {
                        tick = API.goodsManger.ncpUpdateOperateExamReport(params);
                    }

                    break;

                case '农资产品管理-添加和编辑':
                    if (this.type == 1) {
                        tick = API.goodsManger.nzAddOperateExamReport(params);
                    } else {
                        tick = API.goodsManger.nzUpdateOperateExamReport(params);
                    }

                    break;
            }

            tick.then((data) => {
                if (data.code == '0000') {
                    this.$message({
                        message: `${this.type == 2 ? '修改成功' : '新增成功'}`,
                        type: 'success',
                        duration: 1500,
                        onClose: () => {
                            this.closePage();
                        }
                    });
                } else {
                    this.$message.error(res.message);
                }
            });
        },

        closePage() {
            this.$router.go(-1);
        },

        //- 审批
        // 通过或拒绝
        dataFormSubmit(type) {
            if (type == 2 && this.remark == '') {
                // 拒绝
                this.$message.error('请填写拒绝原因');
                return;
            }
            let statusStr = ''; //审核状态 ENABLE: 通过, 0: 未审核, 1: 未通过

            if (type == 1) {
                statusStr = '0';
            } else {
                statusStr = '1:';
            }

            var params = {
                remark: this.remark,
                status: statusStr,
                materialId: this.dataForm.materialId
            };

            var tick;

            switch (this.pageFlag) {
                case '农产品管理-添加和编辑':
                    tick = API.goodsManger.ncpSaveAudit(params);
                    break;

                case '农资产品管理-添加和编辑':
                    tick = API.goodsManger.nzSaveAudit(params);

                    break;
            }

            tick.then((data) => {
                if (data.code == '0000') {
                    this.$message({
                        message: '操作成功',
                        type: 'success',
                        duration: 1500,
                        onClose: () => {
                            this.closePage();
                        }
                    });
                }
            });
        }
    }
};
</script>